 function formatDate (value){
  var date = new Date(value);
  var y = date.getFullYear();
  var m = date.getMonth() + 1;
  m = m < 10 ? ('0' + m) : m;
  var d = date.getDate();
  d = d < 10 ? ('0' + d) : d;
  var h = date.getHours();
  h = h < 10 ? ('0' + h) : h;
  var minute = date.getMinutes();
  var second = date.getSeconds();
  minute = minute < 10 ? ('0' + minute) : minute;
  second = second < 10 ? ('0' + second) : second;
  return y + '-' + m + '-' + d //+ ' ' + h + ':' + minute;// + ':' + second;
  }

function formatDateFull(value) {
  var date = new Date(value);
  var y = date.getFullYear();
  var m = date.getMonth() + 1;
  m = m < 10 ? ('0' + m) : m;
  var d = date.getDate();
  d = d < 10 ? ('0' + d) : d;
  var h = date.getHours();
  h = h < 10 ? ('0' + h) : h;
  var minute = date.getMinutes();
  var second = date.getSeconds();
  minute = minute < 10 ? ('0' + minute) : minute;
  second = second < 10 ? ('0' + second) : second;
  return y + '-' + m + '-' + d + ' ' + h + ':' + minute + ':' + second;
}

function formatTime(value) {
  var date = new Date(value);
  var h = date.getHours();
  h = h < 10 ? ('0' + h) : h;
  var minute = date.getMinutes();
  var second = date.getSeconds();
  minute = minute < 10 ? ('0' + minute) : minute;
  second = second < 10 ? ('0' + second) : second;
  return  h + ':' + minute;// + ':' + second;
}

function checkPhone(value){
  let str = /^1\d{10}$/
  if (str.test(value)) {
    return true
  } else {
    return false
  }
}

const formatDate2 = (dates, type) => {
  let time;
  if (type == 0) {
    // 下一天
    time = (dates).getTime() + 24 * 60 * 60 * 1000;
  } else if (type == 1) {
    // 当前
    time = (dates).getTime();
  } else if (type == 2) {
    // 前一天
    time = (dates).getTime() - 24 * 60 * 60 * 1000;
  }
  var date = new Date(time); // 获取的是前一天日期
  let year = date.getFullYear();
  let month = date.getMonth() + 1;
  month = month < 10 ? ('0' + month) : month;
  let day = date.getDate();
  day = day < 10 ? ('0' + day) : day;
  let str = year + "-" + month + "-" + day;
  return str
}

const getDifferDay = (date1, date2) => {
  let startDate = new Date(date1);
  let endDate = new Date(date2);
  var date = (startDate.getTime() - endDate.getTime()) / (1000 * 60 * 60 * 24);
  return date;
}

function addDay(date) {

}


const wxuuid = function () {
  var s = [];
  var hexDigits = "0123456789abcdef";
  for (var i = 0; i < 36; i++) {
    s[i] = hexDigits.substr(Math.floor(Math.random() * 0x10), 1);
  }
  s[14] = "4"; // bits 12-15 of the time_hi_and_version field to 0010
  s[19] = hexDigits.substr((s[19] & 0x3) | 0x8, 1); // bits 6-7 of the clock_seq_hi_and_reserved to 01
  s[8] = s[13] = s[18] = s[23] = "_";

  var uuid = s.join("");
  uuid = uuid.replace(/_/g, '');
  return uuid
}



module.exports = {
  formatDate: formatDate,
  formatDateFull: formatDateFull,
  formatTime: formatTime,
  checkPhone: checkPhone,
  formatDate2: formatDate2,
  getDifferDay: getDifferDay,
  wxuuid: wxuuid
}